#pragma once

#include "fxcc/core/pch.h"

namespace fxcc
{
    struct FXCC_API AssertManager
    {
        static std::string RootPath() 
        {
            return FXCC_ASSERT_PATH;
        }

        static std::string normalizePath(const std::string& path)
        {
            std::string normalized = path;
            std::replace(normalized.begin(), normalized.end(), '\\', '/');

            auto normalized_p = fs::relative(normalized, "./");
            return normalized_p.string();
        };
        static std::string GetFile(const std::string& relativePath) 
        {
            fs::path _p = fs::path(RootPath()) / fs::path(relativePath);
            if (!fs::exists(_p))
            {
                //ztclog::warn("failed to find file %s", relativePath.c_str());
            };
            _p = fs::absolute(_p);
            return normalizePath(_p.string());
        }
        static std::string GetRelativeFile(const std::string& relativePath)
        {
            fs::path _p = fs::path(RootPath()) / fs::path(relativePath);
            if (!fs::exists(_p))
            {
                //ztclog::warn("failed to find file %s", relativePath.c_str());
            };
            _p = fs::absolute(_p);
            return normalizePath(_p.string());
        }
        static std::string GetAbsoluteFile(const std::string& relativePath)
        {
            fs::path _p = fs::path(RootPath()) / fs::path(relativePath);
            if (!fs::exists(_p))
            {
                ztclog::warn("failed to find file %s", relativePath.c_str());
            };
            _p = fs::absolute(_p);
            return (_p.string());
        }
        static std::string readFile(const std::string& path)
        {
            std::ifstream ifs(path, std::ios::in);

            if (!ifs.is_open())
            {
                ztclog::info("cannot open file from %s ", path.c_str());
                return "";
            }

            std::string text = std::string(std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>());
            return text;
        }
        static std::string readFilePath(const std::string& path)
        {
            std::string absolutePath = GetFile(path);
            return readFile(absolutePath);
        }

        static AssertManager &Inst()
        {
            static AssertManager res;
            return res;
        }
    };
}